package started;

import java.io.FileReader;
import java.util.Properties;

import utilities.GetMyIp;
import entility.Machine;

public class ReadProperties {

	public Machine  getPrimaryServer()
	{
		
		
		try{
			
			
			
			Properties props = new Properties();
			props.load(new FileReader("server.properties"));
			Machine me = new Machine(props.getProperty("primary_server_ip").trim(), Integer.parseInt(props.getProperty("primary_server_port").trim()));
			return me;
		}
		catch(Exception e )
		{
			e.printStackTrace();

		}
		return null;

	}

	public Machine getThisServer()
	{

		try{

			GetMyIp getMyip = new GetMyIp();

			Properties props = new Properties();
			props.load(new FileReader("server.properties"));
			String ip = getMyip.getIp();
			
			if(ip == null)
			{
				ip = props.getProperty("server_ip").trim();
			}
			
			
			Machine server = new Machine(ip, Integer.parseInt(props.getProperty("server_port").trim()));
			return server;
		}
		catch(Exception e )
		{
			e.printStackTrace();

		}
		return null;

	}

}
